﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using Shpm.App.Master.Dao;
using Shpm.App.Commons.Utils;
using Shpm.App.Master.Bean;
using Shpm.System;


    public partial class App_Master_PersonInfoSrh : System.Web.UI.Page
    {

        private const string COMMAND_SEARCH = "DoSearch";
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!this.IsPostBack)
            {
                ViewState["ParamPersonId"] = Convert.ToString(Context.Items["ParamPersonId"]);
                ViewState["ParamNameC"] = Convert.ToString(Context.Items["ParamNameC"]);
                ViewState["ParamCommand"] = Convert.ToString(Context.Items["ParamCommand"]);

                // 接收传递参数为分页编号
                if (Context.Items.Contains("ParamPageIndex"))
                {
                    GridView1.PageIndex = Convert.ToInt32(Context.Items["ParamPageIndex"]);
                }
                this.personId.Text = Convert.ToString(Context.Items["InpPersonId"]);
                this.nameC.Text = Convert.ToString(Context.Items["InpNameC"]);

                this.GridView1.DataSourceID = null;
            }
        }



        protected void memberIn_Click(object sender, EventArgs e)
        {
            // 传递控件输入内容
            Context.Items["InpPersonId"] = this.personId.Text;
            Context.Items["InpNameC"] = this.nameC.Text;

            // 传递检索条件
            Context.Items["ParamPersonId"] = Convert.ToString(ViewState["ParamPersonId"]);
            Context.Items["ParamNameC"] = Convert.ToString(ViewState["ParamNameC"]);
            Context.Items["ParamCommand"] = Convert.ToString(ViewState["ParamCommand"]);

            Context.Items["ParamPageIndex"] = this.GridView1.PageIndex;
            ControllerUtils.Transfer(this.Context, "~/App/Master/PersonDetailForm.aspx",true);
        }



      /*  protected void modify_Command(object sender, CommandEventArgs e)
        {
            int   index   =   Convert.ToInt32(e.CommandArgument);//获取行号   
            GridViewRow   row   =   GridView1.Rows[index];//获取该行   
            string s = row.Cells[0].Text;//该行第二列数据   

        }*/

        protected void GridView1_RowCommand(object sender, CommandEventArgs e)
        {
            if (e.CommandName == "Select")
            {
                // 传递控件输入内容
                Context.Items["InpPersonId"] = this.personId.Text;
                Context.Items["InpNameC"] = this.nameC.Text;

                // 传递检索条件
                Context.Items["ParamPersonId"] = Convert.ToString(ViewState["ParamPersonId"]);
                Context.Items["ParamNameC"] = Convert.ToString(ViewState["ParamNameC"]);
                Context.Items["ParamCommand"] = Convert.ToString(ViewState["ParamCommand"]);

                Context.Items["ParamPageIndex"] = this.GridView1.PageIndex;


                int index = Convert.ToInt32(e.CommandArgument);//获取行号
                this.Context.Items["PERSON_ID"] = ((GridView)sender).Rows[index].Cells[0].Text;


                ControllerUtils.Transfer(this.Context, "~/App/Master/PersonDetailForm.aspx", true);

            }

        }
        protected void search_Click(object sender, EventArgs e)
        {

            if (this.ComValidator1.DoValidator())
        {
            // 保存控件状态为检索条件
            ViewState["ParamPersonId"] = this.personId.Text;
            ViewState["ParamNameC"] = this.nameC.Text;
            ViewState["ParamCommand"] = COMMAND_SEARCH;
            GridView1.PageIndex = 0;  
        }
        else 
        {
            ((Design_MasterPage)this.Master).InfoMessage = ComValidator1.ErrorMessage;     

            this.GridView1.DataSourceID = null;
        }


          
            
        }

        protected override void OnPreRender(EventArgs e)
        {
            base.OnPreRender(e);



            //if (COMMAND_SEARCH.Equals(ViewState["ParamCommand"]))
           // {

                // 构建检索条件对象
                PersonInfoDao dao = new PersonInfoDao();
                PersonTableBean bean = new PersonTableBean();
                bean.PersonId = (string.IsNullOrEmpty(Convert.ToString(ViewState["ParamPersonId"]))) ? null : new Nullable<int>(Convert.ToInt32(ViewState["ParamPersonId"]));
                bean.NameC = (string.IsNullOrEmpty(Convert.ToString(ViewState["ParamNameC"]))) ? null : (Convert.ToString(ViewState["ParamNameC"]));

                IList list = dao.FindAll(bean);
                this.GridView1.DataSource = list;
                this.GridView1.DataBind();

                resultTable.Visible = list.Count > 0;

                if (list.Count == 0)
                {
                    ((Design_MasterPage)this.Master).InfoMessage =
                        Convert.ToString(HttpContext.GetGlobalResourceObject(Constants.GLOBAL_RESOURCE_NAME, "E0005"));
                }
           // }
           // else
           // {
           //     resultTable.Visible = false;
           // }
        }

        protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
        {
            // 设置分页编号
            GridView1.PageIndex = e.NewPageIndex;
        }
    

}
